package ahblue.cn.tanzi.ui.msg;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.IdRes;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentTransaction;
import android.widget.FrameLayout;

import ahblue.cn.tanzi.R;
import ahblue.cn.tanzi.jmessage.im.base.BaseActivity;
import ahblue.cn.tanzi.jmessage.im.ui.fragment.ContactsFragment;
import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * @author pink-jackstraw
 * @date 2018/11/10
 * @describe 好友列表
 */
public class FriendlistActivity extends BaseActivity {

    @BindView(R.id.rlreplce)
    FrameLayout rlreplce;
//    @BindView(R.id.recy)
//    RecyclerView recyview;
//    @BindView(R.id.empty)
//    RelativeLayout empty;
//    @BindView(R.id.refresh)
//    SwipeRefreshLayout swipeRefreshLayout;
//    private BRAdapter<FriendModel> adapter;
//    private List<FriendModel> dataList = new ArrayList<>();
//    private int page = 0;

//    private Handler mHandler = new Handler() {
//        @Override
//        public void handleMessage(Message msg) {
//            super.handleMessage(msg);
//            switch (msg.what) {
//                case 1:
//                    swipeRefreshLayout.setRefreshing(false);
//                    adapter.notifyDataSetChanged();
//                    //swipeRefreshLayout.setEnabled(false);
//                    break;
//                default:
//                    break;
//            }
//        }
//    };

    public static void into(Activity activity) {
        activity.startActivity(new Intent(activity, FriendlistActivity.class));
    }

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_friend_list_0);
        ButterKnife.bind(this);
        ContactsFragment jdFragment = new ContactsFragment();
        replaceFragment(R.id.rlreplce,jdFragment);
//        initView();
//        initData();
    }

    private void initData() {
//        FriendModel.getFriends(this, LoginResultModel.getToken(this), new FriendModel.FriendListStatus() {
//            @Override
//            public void conver(List<FriendModel> model) {
//                Log.e("getFriends", "conver: ");
//                if (null != model) {
//                    dataList.addAll(model);
//                }
//                if (dataList.size() > 0) {
//                    empty.setVisibility(View.GONE);
//                    swipeRefreshLayout.setVisibility(View.VISIBLE);
//                } else {
//                    empty.setVisibility(View.VISIBLE);
//                    swipeRefreshLayout.setVisibility(View.GONE);
//                }
//                adapter.notifyDataSetChanged();
//            }
//        });

    }

    private void initView() {
//        recyview.setLayoutManager(new LinearLayoutManager(this));
//        adapter = new BRAdapter<FriendModel>(this, R.layout.activity_friend_item, dataList) {
//            @Override
//            protected void convert(RvHolder holder, FriendModel specalModel, int position) {
//                ImageLoadUtil.load(TanZiApplication.getContext(), specalModel.avatar, holder.getView(R.id.icon));
//                holder.setText(R.id.name, specalModel.username);
//            }
//        };
//        recyview.setAdapter(adapter);
//        swipeRefreshLayout.setColorSchemeResources(R.color.colorPrimary);
//        swipeRefreshLayout.setSize(SwipeRefreshLayout.LARGE);
////        swipeRefreshLayout.setProgressBackgroundColor(R.color.colorAccent);
//        //swipeRefreshLayout.setPadding(20, 20, 20, 20);
//        //swipeRefreshLayout.setProgressViewOffset(true, 100, 200);
//        //swipeRefreshLayout.setDistanceToTriggerSync(50);
//        swipeRefreshLayout.setProgressViewEndTarget(true, 100);
//        swipeRefreshLayout.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
//            @Override
//            public void onRefresh() {
//                new Thread(new Runnable() {
//                    @Override
//                    public void run() {
//                        dataList.clear();
//                        page = 0;
//                        initData();
//                        mHandler.sendEmptyMessage(1);
//                    }
//                }).start();
//            }
//        });
    }

//    @OnClick(R.id.btn_back)
//    public void onViewClicked() {
//        finish();
//    }

    public void replaceFragment(@IdRes int id_content, Fragment fragment) {
        FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();
//        transaction.setCustomAnimations(anim_in, anim_out);
        transaction.replace(id_content, fragment);
        transaction.commitAllowingStateLoss();
    }
}
